package com.zhaiweijia.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaiweijia.dao.DamDao;
import com.zhaiweijia.entity.Dam;
import com.zhaiweijia.entity.DamType;
import com.zhaiweijia.service.DamService;
@Service
public class DamServiceImpl implements DamService{
	@Autowired
	public DamDao dao;

	@Override
	public DamType getTidByTname(String tname) {
		// TODO Auto-generated method stub
		return dao.getTidByTname(tname);
	}

	@Override
	public void add(Dam dam) {
		dao.add(dam);
		
	}

	@Override
	public PageInfo findAll(Integer pageNum, Integer pageSize,Integer avgRain,Integer timeOfRain) {
		
		PageHelper.startPage(pageNum, pageSize);
		
		
		List<Dam> list = dao.findAll();
		for (Dam dam : list) {
			if(avgRain !=null && timeOfRain !=null) {
				Float rk=avgRain * timeOfRain * dam.getRainArea() * 1000;
				Float s=rk-(dam.getVolumeTotal() - dam.getVolumeNow());
				if(s<0) {
					dam.setStatus("安全");
				}else {
					Float xh=dam.getVolumeDischarge() * timeOfRain * 3600;
					if(rk>xh) {
						dam.setStatus("漫坝");
					}else {
						dam.setStatus("超限");
					}
				
				}
				
				
			}
		}
		
		PageInfo info = new PageInfo(list);
		
		
		return info;
	}
	
	
}
